@ECHO OFF


REM afti-2013-oop-nsu.googlecode.com

SET SvnDir=%APPDATA%\Subversion\auth\svn.simple
SET ProjectName=afti-2013-oop-nsu.googlecode.com
SET UserName=

SET FileName=

IF NOT EXIST "%SvnDir%" EXIT /B 0

DIR /B/A-D "*" >nul 2>&1 && (
	FOR /F "tokens=*" %%F IN ('DIR /B/A-D "*"') DO (
		IF "%%~xF"=="" (
			FIND /i "%ProjectName%" "%%F" >nul 2>&1 && (
				IF NOT "%UserName%"=="" (
					FIND /i "%UserName%" "%%F" >nul 2>&1 && (
						SET FileName="%%~F"
					)
				) ELSE (
					SET FileName="%%~F"
				)
			)
		)
	)
)

IF "%FileName%"=="" (
	IF "%UserName%"=="" (
		ECHO Svn auth record for project %ProjectName% was not found.
	) ELSE (
		ECHO Svn auth record for project %ProjectName%, user %UserName% was not found.
	)
	PAUSE
) ELSE (
	XCOPY /C /Y "%FileName%" "%SvnDir%" >nul 2>&1
)

EXIT /B 0